#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    vector<vector<int>> generateMatrix(int n) {
        vector<vector<int>> v(n, vector<int>(n, 0));
        int startx = 0, starty = 0;
        int count = 1, offset = 1;
        int i = 0, j = 0;
        int loop = n / 2;
        while (loop)
        {
            i = startx;
            j = starty;
            for (j = starty; j < n - offset; j++)
            {
                v[i][j] = count++;
            }
            for (i = startx; i < n - offset; i++)
            {
                v[i][j] = count++;
            }
            for (; j > starty; j--)
            {
                v[i][j] = count++;
            }
            for (; i > startx; i--)
            {
                v[i][j] = count++;
            }

            startx++;
            starty++;
            offset++;
            loop--;
        }

        if (n % 2 == 1)
        {
            v[n / 2][n / 2] = count;
        }

        return v;
    }
};
int main()
{
    Solution().generateMatrix(4);
    return 0;
}